package idiet.dao.hibernate;

import idiet.bean.CurrentId;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("currentIdDao")
public class CurrentIdDao extends BaseDao {
	public CurrentId getCurrentIdById(int currentIdId){
		return (CurrentId) this.sessionFactory
				.getCurrentSession()
				.createCriteria(CurrentId.class)
				.add(Restrictions.eq("id", currentIdId))
				.uniqueResult();
	}
	public CurrentId getCurrentIdsByTableName(String name){
		return (CurrentId) this.sessionFactory
				.getCurrentSession()
				.createCriteria(CurrentId.class)
				.add(Restrictions.like("tableName",name))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<CurrentId> getCurrentIds(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(CurrentId.class)
				.list();
	}
	public void createCurrentId(CurrentId currentId){
		this.sessionFactory
		.getCurrentSession()
		.save(currentId);
	}
	public void updateCurrentId(CurrentId currentId){
		this.sessionFactory
		.getCurrentSession()
		.update(currentId);
	}
	public void deleteCurrentId(CurrentId currentId){
		this.sessionFactory
		.getCurrentSession()
		.delete(currentId);
	}
}
